import java.util.Scanner;

/**
 * 【程序39】   
 * 题目：编写一个函数，输入n为偶数时，调用函数求1/2+1/4+...+1/n,
 * 当输入n为奇数时，调用函数1/1+1/3+...+1/n
 */
public class test39 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入一个整数：");
        double number = sc.nextDouble();
        if (number % 2 == 0)
            method1(number);
        else
            method2(number);
    }

    private static void method2(double number) {
        double sum = 0;
        for (double i = number; i >= 1; i = i - 2) {
            sum = sum + 1 / i;
        }
        System.out.println("和为：" + sum);
    }

    private static void method1(double number) {
        double sum = 0;
        for (double i = number; i >= 2; i = i - 2) {
            sum = sum + 1 / i;
        }
        System.out.println("和为：" + sum);
    }
}
